//存放查找/分类的商品列表
import {
  defineStore
} from "pinia";
import { reactive } from "vue";

export const useProductsStore = defineStore("products", () => {
  const products = reactive({
    list: [],
    search: "",
    current: 0,
    pageSize: 8,
    total: 0,
  });

  const setProducts = (list) => {
    products.list = list;
  }

  const setPage = (total, pageSize,current) => {
    products.total =  parseInt(total, 10);
    products.pageSize = parseInt(pageSize, 10);
    products.current = parseInt(current, 10);
  }

  const clearProducts = () => {
    products.list = [];
  }

  const getProducts = () => {
    return products.list;
  }

  return {
    products,
    setProducts,
    setPage,
    getProducts,
    clearProducts
  };
})